$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'operation/book/list',
        datatype: "json",
        colModel: [	
			{ label: 'RFID编号', name: 'rfidCode',index:"rfid_code",key:true,width:220,align:'center' },
			{ label: '书籍名称', name: 'bookName',index:"book_name" ,width:180,align:'center' },
			{ label: '价格(元)', name: 'price', index:"price",width:70 ,align:'center'},
			{ label: 'ISBN编号', name: 'isbnNo',index:"isbn_no",width:140 ,align:'center' },
			{ label: '投放时间', name: 'putonDate',index:"puton_date" ,width:140 ,align:'center'},
			{ label: '最近借阅开始时间', name: 'createTime',index:"borrow_time_start",width:140 ,align:'center'},
			{ label: '最近借阅结束时间', name: 'modifyTime',index:"borrow_time_end",width:140,align:'center' },
			{ label: '出借率', name:'borrowRate',index:"borrow_rate",width:90,align:'center'},
			{ label: '出借总费用', name:'bookSumMoney',index:"book_sum_money",width:90,align:'center'},
			{ label: '借阅次数', name: 'bookBorrowCount',index:"book_borrow_count",width:80,align:'center',
				formatter:function(value, options, rowObject){
					return "<a onclick=\"bookBorrowCountHtml('"+rowObject.rfidCode+"')\">"+rowObject.bookBorrowCount+"</a>"
				}
			},
			{ label: '最近借阅客户', name: 'userName',index:"user_name",width:100,align:'center'},
			/*{ label: '最近借阅时间', name: 'borrowTimeStart',index:"borrow_time_start",width:100,align:'center'},*/
			{ label: '书柜编号', name: 'shelfCode',formatter:function(cellvalue, options, rowObject){
				var bookShelfCode = "";
				if(rowObject.borrowedStatus==2){
					//return rowObject.shelfCode;//0,
					bookShelfCode = rowObject.shelfCode
				}else{
					bookShelfCode = rowObject.restituteShelfCode==null?"":rowObject.restituteShelfCode;
					//return rowObject.restituteShelfCode==null?"":rowObject.restituteShelfCode;
				}
				return "<a  onclick=\"bookShelfMonitoringHtml('"+bookShelfCode+"')\">"+bookShelfCode+"</a>"
			},index:"credit_value",width:90,align:'center',sortable:false},
			{ label: '书格编号', name: 'gridCode',formatter:function(cellvalue, options, rowObject){
				if(rowObject.borrowedStatus==2){
					return rowObject.gridCode;
				}else{
					return rowObject.restituteGridCode==null?"":rowObject.restituteGridCode;
				}
			},index:"credit_value",width:100,align:'center',sortable:false},
			{ label: '出借状态', name: 'borrowedStatus',formatter:function(cellvalue, options, rowObject){
				if(rowObject.borrowedStatus==null){
					return "未上架";
				}else if(rowObject.borrowedStatus==0){
					return "上架";
				}else if(rowObject.borrowedStatus==1){
					return "下架";
				}else if(rowObject.borrowedStatus==2){
					return "借阅";
				}
			},index:"borrowed_status",width:80,align:'center'},
			
			/*{ label: '黑名单', name: 'id',index:"id",width:60 ,align:'center'},*/
			{ label: '维护状态', name: 'status',index:"maintain_status" ,width:80,align:'center',sortable:false,
				formatter:function(cellvalue, options, rowObject){
					if(rowObject.status==1||rowObject.status==null){
						return "正常";
					}else if(rowObject.status==0){
						return "报修";
					}else if(rowObject.status==2){
						return "维护";
					}else if(rowObject.status==3){
						return "报废";
					}
				}
			},
			{ label: '销售状态', name: 'sellStatus',index:"sell_status",width:80,align:'center',sortable:false,
				formatter:function(cellvalue, options, rowObject){
					if(rowObject.sellStatus==0||rowObject.sellStatus==null){
						return "未销售";
					}else if(rowObject.sellStatus==1){
						return "已销售";
					}
				}	
			},
			/*{ label: '操作', name: '操作',formatter:function(cellvalue, options, rowObject){
				return "<a onclick=\"update('"+rowObject.rfidCode+"')\">编辑</a>"
			},index:"comment_count",width:60,align:'center' },*/
			{ label: '操作', name: '操作',index:"comment_count",width:60,align:'center',
				formatter:function(cellvalue, options, rowObject){
					return "<a onclick=\"bookBorrowUpdateHtml('"+rowObject.rfidCode+"')\">编辑</a>"
				} 
			},
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        autoScroll:true,
        shrinkToFit:false,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        
    });
});
sessionStorage.book_borrow_page_num=''; //$('#jqGrid').getGridParam('page');//$("#jqGrid").jqGrid('getGridParam','page');
var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			bookName: null,
			rfidCode: null,
			bookBorrowStartTimeA: null,
			bookBorrowStartTimeB: null,
			bookBorrowEndTimeA: null,
			bookBorrowEndTimeB: null
		},
		showList: true,
		title: null
	},
	methods: {
		query: function () {
			vm.reload();
		},
		generator: function() {
			var tableNames = getSelectedRows();
			if(tableNames == null){
				return ;
			}
			location.href = baseURL + "sys/generator/code?tables=" + JSON.stringify(tableNames);
		},
		getInfo: function(id){
			$.get(baseURL + "accountcash/info/"+id, function(r){
                vm.accountCash = r.accountCash;
            });
		},
		bookBorrowLayer:function(rfidCode){
			layer.open({
				type : 2,
				title : '编辑',
				closeBtn: 1,
				maxmin : true,
				shadeClose : true, // 点击遮罩关闭层
				area : [ '300px', '200px' ],
				content : ['./book-borrow-update.html?rfidCode=' + rfidCode,'no']
			});
		},
		bookBorrowCount:function(rfidCode){
			layer.open({
				type : 2,
				title : '书籍借阅次数',
				closeBtn: 1,
				maxmin : true,
				shadeClose : true, // 点击遮罩关闭层
				area : [ '1120px', '620px' ],
				content : ['./book-borrow-count.html?rfidCode=' + rfidCode + 
					'&bookBorrowStartTimeA=' + vm.q.bookBorrowStartTimeA +
					'&bookBorrowStartTimeB=' + vm.q.bookBorrowStartTimeB +
					'&bookBorrowEndTimeA=' + vm.q.bookBorrowEndTimeA +
					'&bookBorrowEndTimeB=' + vm.q.bookBorrowEndTimeB
					,'no']
			});
		},
		bookShelfMonitoringLayer: function(code){
			layer.open({
				type : 2,
				title : '书籍监控页面',
				closeBtn: 1,
				maxmin : true,
				shadeClose : true, // 点击遮罩关闭层
				area : [ '730px', '700px' ],
				content : ['./book-shelf-monitoring.html?code='+code,'no']
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam', {
				postData : {
					'bookName' : vm.q.bookName,
					'rfidCode' : vm.q.rfidCode,
					'bookBorrowStartTimeA' : vm.q.bookBorrowStartTimeA,
					'bookBorrowStartTimeB' : vm.q.bookBorrowStartTimeB,
					'bookBorrowEndTimeA' : vm.q.bookBorrowEndTimeA,
					'bookBorrowEndTimeB' : vm.q.bookBorrowEndTimeB
				},
				page : page
			}).trigger("reloadGrid");
		}
	}
});